package com.lq.schoolshop.dao;

import com.lq.schoolshop.pojo.ShopCar;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author
 * @Date2021/1/7 10:23
 * @Version V1.0
 * 订单表
 **/
public interface OrderMapper {

   //1.根据购物车ID 查询到gid 和数量
   List<ShopCar> selShopCarAllById(int []id);

   //2.根据gid查询到商品单价 插入到订单表
   @Insert("INSERT  INTO orders(id,orderuuid,uid,price,createtime,address,phone,payment,STATUS,deliverystatus) VALUES (default,#{orderuuid},#{uid},#{price},NOW(),#{address},#{phone},#{payment},#{status},#{deliverystatus})")
   int insertOrderAll(@Param("orderuuid") String orderuuid,@Param("uid") int uid,@Param("price") double price,@Param("address")String address,@Param("phone") String phone,@Param("payment") String payment,@Param("status")String status,@Param("deliverystatus") String deliverystatus);

    //3.根据gid查询到商品数量 插入到订单详情表 以及订单表的 订单ID
    @Insert("INSERT INTO orderdetail VALUES (DEFAULT,#{oid},#{gid},#{count},#{moneytotal},null)")
    int insertOrderDetailAll(@Param("oid") String oid,@Param("gid") int gid,@Param("count") int count,@Param("moneytotal") double moneytotal);

    //4.商品销量+1  商品库存-1   但是商品库存要做负数检测 以免发生负数的情况
    @Update(" UPDATE goods SET sellcount = sellcount + #{sellcount},COUNT = COUNT - #{count} WHERE id = #{id}")
    int updateGoodsSellCount(@Param("sellcount")int sellcount,@Param("count")int count,@Param("id") int id);

    //5.删除购物车相关信息  根据购物车ID删除 (批量删除)  //该方法在购车车Mapper里面有 所以不重复写
      //int deleteShopCarById(int []array);
}
